#include"work1.h"

int main()
{
	int choice;
    int i;
	
	/*使用结构体*/
	Bookinfor books[100];
	Reader rea[100];
	Admin adm [100];
	Borrowinfor bor [100];	
	
	/*记录录入的数量*/
	int bookNum = 0;
	int reaNum = 0;
	int admNum = 0;
	int borrowNum = 0;
	
	/*记录原始数量，在信息保存的函数中实现增加功能*/
	int primal_bookNum;
	int primal_reaNum;
	int primal_admNum;
	int primal_borrowNum;
	
	
	
	while (1)
	{
		Menu();   //调用菜单函数
		
		scanf("%d", &choice);
		
	  switch (choice)
	  {
		case 1:     //书籍信息录入或增加
			primal_bookNum = bookNum;
			printf("请输入需要录入(增加)的数量:");
			scanf("%d", &bookNum);			
			bookNum += primal_bookNum;
			
			Input_book(books, bookNum, primal_bookNum);   
			break;
		case 2:     //读者信息录入或增加			 
			primal_reaNum = reaNum;
			printf("请输入需要录入(增加)的数量:");
			scanf("%d", &reaNum);
			reaNum += primal_reaNum;
			
			Input_reader(rea, reaNum, primal_reaNum);
		    break;
		case 3:     //管理员信息录入或增加
			primal_admNum = admNum;
			printf("请输入需要录入(增加)的数量:");
			scanf("%d", &admNum);
			admNum += primal_admNum;
			
			Input_adm(adm, admNum, primal_admNum);
			break;
	    case 4:     //借阅情况录入或增加
			primal_borrowNum = borrowNum;
			printf("请输入需要录入(增加)的数量:");
			scanf("%d", &borrowNum);
			borrowNum += primal_borrowNum;
			
			Input_borrowinfor(bor, borrowNum, primal_borrowNum);
			
			for(i=0; i<borrowNum; i++)
			{
				if (strcmp(bor[i].book, books[i].bookname) == 0)
				{
					books[i].num -=1;
				}
			}
			break;
		case 5:     //查询书籍信息
			system("cls");
			Check_book(books, bookNum);
			break;
		case 6:     //查询读者信息
			system("cls");
			Check_reader(rea, reaNum);
			break;
		case 7:     //查询管理员信息
			system("cls");
			Check_admin(adm, admNum);
			break;
		case 8:     //查询借阅情况
			system("cls");
			Check_borrowinfor(bor, borrowNum);
			break;
		case 9:     //修改书籍信息
			system("cls");
			Revise_book(books, bookNum);
			break;
		case 10:    //修改读者信息
			system("cls");
			Revise_reader(rea, reaNum);
			break; 
		case 11:    //修改管理员信息
			system("cls");
			Revise_admin(adm, admNum);
			break;
		case 12:    //修改借阅情况
			system("cls");
			Revise_borrowinfor(bor, borrowNum);
			break;
		case 13:    //删除读者信息
		    system("cls");
			reaNum = Delete_reader(rea, reaNum);
			break;
		case 14:    //删除管理员信息
		    system("cls");
			admNum = Delete_admin(adm, admNum);
			break;
		case 15:    //保存所有信息
			Save_book(books, bookNum);
			Save_reader(rea, reaNum);
			Save_admin(adm, admNum);
			Save_borrowinfor(bor, borrowNum);
			
			system("pause");
			system("cls");
			break;
		case 16:   /*读取所有信息*/
			/*调用函数并记录个数*/
			bookNum = Read_book(books);
			reaNum = Read_reader(rea);
			admNum = Read_admin(adm); 
			borrowNum = Read_borrowinfor(bor);
			
			system("pause");
			system("cls");
			break;
		case 17:    //退出
		    printf("欢迎下次使用.\n");
		    return 1;   //跳出循环
		    break;	
		default:
		    printf("输入有误，请重新输入.\n");
		    system("pause");
			system("cls");
			break;	
		}	
	}
	return 0;
}